package com.activititest.controller;


import com.activititest.appentity.EmEnterpriseInfor;
import com.activititest.appentity.EmPollutant;
import com.activititest.appentity.Response;
import com.activititest.entity.EmEnterprise;
import com.activititest.entity.VEmEnterprisepoll;
import com.activititest.service.IEmTaskCmdPolltantService;
import com.activititest.service.IVEmEnterprisepollService;
import org.apache.velocity.util.ArrayListWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

///**
// * <p>
// *  前端控制器
// * </p>
// *
// * @author mfx
// * @since 2020-05-29
// * 企业污染物
// */
@RestController
@RequestMapping("/activititest/v-em-enterprisepoll")
public class VEmEnterprisepollController {
    @Autowired
private IVEmEnterprisepollService  emEnterprisepollService;
    @PostMapping("getenterprisepoll/")
    public Response<EmEnterpriseInfor> getEnterprisepoll(@RequestParam("enterpriseid") String enterpriseid){

        List<VEmEnterprisepoll> enterprises = (List<VEmEnterprisepoll>) emEnterprisepollService.listByMap(new HashMap() {{
            put("enterprise_id", enterpriseid);
        }});
        VEmEnterprisepoll vEmEnterprisepoll = enterprises.get(0);
        EmEnterpriseInfor emEnterpriseInfor = new EmEnterpriseInfor();
        emEnterpriseInfor.setEnterprise_address(vEmEnterprisepoll.getEnterpriseAddress());
        emEnterpriseInfor.setEnterprise_id(String.valueOf(vEmEnterprisepoll.getEnterpriseId()));
        emEnterpriseInfor.setEnterprise_latitude(vEmEnterprisepoll.getEnterpriseLatitude());
        emEnterpriseInfor.setEnterprise_longitude(vEmEnterprisepoll.getEnterpriseLongitude());
        emEnterpriseInfor.setEnterprise_name(vEmEnterprisepoll.getEnterpriseName());
        List<EmPollutant> eps=new ArrayList();
        EmPollutant emPollutant;
        for(VEmEnterprisepoll emEnterprisepoll:enterprises){
            emPollutant = new EmPollutant(emEnterprisepoll.getPollutantId(),emEnterprisepoll.getPollutantType(),emEnterprisepoll.getPollutantName());
            eps.add(emPollutant);
        }
        emEnterpriseInfor.setEmPollutants(eps);
        Response euserResponse = new Response();
        euserResponse.setCode(200);
        euserResponse.setData(emEnterpriseInfor);
        euserResponse.setMsg("yes");

        return euserResponse;
    }
}

